
* Endogenous controls

use "$OUTDATA/ddd-reds_withmain_v2.dta", clear

********************************************************************************
* Sample selection
********************************************************************************

rename yearbirth yearb
gen hindu1 = (muslim == 0)
gen christian = relig == 4
replace hindu = relig == 1

rename post dow_cohort

rename dow99 dow_99
sum dow_99,d
drop if dow_99>=r(p99) & dow_99!=.
gen missingdow = dow_99 == .
// Karnataka and Maharashtra had issues with missing dowry data (see appendix of Chiplunkar and Weaver)
// In Maharashtra surveyors correctly recorded if dowry was not paid (value of zero), but in nearly all cases where it was paid, they did not record the value. As a result, they recorded a missing value for the dowry payment field in that situation.
// In Karnataka cases where the respondents did not pay dowry were recorded as missing values.

replace missingdow = . if state == 10 | state == 7

sort year_marriage

replace dow_99 = dow_99/1000
replace downet_99 = downet_99/1000

drop _merge
// merge with deflate data
merge m:1 year_marriage using "$OUTDATA/deflatedow"

rename year_marriage yy_1marr
keep if yy_1marr >= 1975

gen dowTreat = dow_cohort*hindu1

gen yearb1975 = (yearb<1975)
replace  yearb1975 =. if yearb == .

// zero dowry dummy
gen zdow=dow_99==0
replace zdow=. if dow_99==.

gen scstbc = (caste_sc == 1 | caste_st == 1 | caste_obc == 1)
gen rural = 1
label var dow_cohort "Post"
label var hindu1 "Non-Muslim"

gen marr_age = yy_1m - yearb
gen age = 1999 - yearb


// main wife deck
gen dow_mainwife = dow_99 if deck8==1
replace dow_mainwife = . if deck8==.

* Labels

label var dow_99 "Dowry"
label var downet_99 "Net Dowry"
label var zdow "No Dowry"
label var missingdow "Missing Dowry"

label var scstbc "SC/ST/OBC"
label var rural "Rural"
label var muslim "Muslim"
label var christian "Christian"
label var hindu "Hindu"
label var primary "Primary School"
label var secondary "Secondary School"  
label var primary_spouse "Husband Primary School"
label var secondary_spouse "Husband Secondary School"
label var years_schooling "Years of Schooling"
label var years_schooling_spouse "Husband Years of Schooling"
label var owns_land "Land Ownership"  
label var hh_members "Household Size"  
label var marr_age "Age at Marriage"  
label var wealth "Wealth Index"
label var feduc " Wife Father Years Schooling"
label var landown "Natal Family Owns Land"

global cov "scstbc rural christian hindu"
global cov1 "wealth years_schooling hh_members"
global cov2 "years_schooling_spouse "
global fe1   "i.state i.yy_1marr"
global fe2   "i.state i.yearb"
global did 	 "i.dow_cohort##i.hindu1"

save "$OUTDATA/REDS_sample_withendogvars.dta", replace
